package com.bizihang.rabbitmq.productor;

import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import javax.annotation.PostConstruct;

@SpringBootApplication
public class Application {
	@Autowired
	RabbitTemplate rabbitTemplate;

	@Bean
	Queue helloQueue() {
		Queue queue = new Queue("hello");
		return queue;
	}

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}

	@PostConstruct
	public void init() {
		for (int i = 0; i < 10; i++) {
			rabbitTemplate.convertAndSend("hello", "hello" + i);
		}
	}
}
